<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="/common/inc::header"/>
<body>
<form class="layui-form" id="bdForm" style="margin-left: 10%">
    <input name="bdTeamId" id="bdTeamId" type="hidden"/>
    <br/>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名:</label>
        <div class="layui-input-inline">
            <input type="text" name="userName" id="userName" placeholder="请输入姓名" autocomplete="off"
                   class="layui-input" lay-verify="required">
        </div>
    </div>
    <hr class="layui-bg-gray">
    <div class="layui-form-item">
        <label class="layui-form-label">手机:</label>
        <div class="layui-input-inline">
            <input type="text" name="telNo" id="telNo" placeholder="请输入手机号码" autocomplete="off"
                   class="layui-input" lay-verify="required|phone|number">
        </div>
    </div>
    <hr class="layui-bg-gray">
    <div class="layui-form-item">
        <label class="layui-form-label">账号:</label>
        <div class="layui-input-inline">
            <input type="text" name="account" id="account" placeholder="请输入登陆账号" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <hr class="layui-bg-gray">
    <div class="layui-form-item">
        <label class="layui-form-label">密码:</label>
        <div class="layui-input-inline">
            <input type="password" name="password" id="password" required placeholder="请输入密码"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <button class="layui-btn" id="formSubmit" lay-submit="" lay-filter="formSubmit" style="display: none">立即提交</button>
</form>
<script th:replace="/common/inc::incJs"></script>
<script>
    var form = layui.form;
    var successCallback;
    var id = getQueryString("id");
    $("#bdTeamId").val(id);

    //监听提交
    form.on('submit(formSubmit)', function (data) {
        if (id != "") {
            $.post('/agent/security/bdUserInfo/update', data.field, function (res) {
                if (res.code < 0) {
                    layer.msg(res.message);
                }
                else {
                    layer.msg('操作成功');
                    successCallback && successCallback();
                }
            });
            return false;
        }
        else {
            $.post('/agent/security/bdUserInfo/addTeam', data.field, function (res) {
                if (res.code < 0) {
                    layer.msg(res.message);
                }
                else {
                    layer.msg('操作成功');
                    successCallback && successCallback();
                }
            });
            return false;
        }
        return false;
    });

    var formSubmit = function (callback) {
        successCallback = callback;
        $("#formSubmit").click();
    }


    $(function () {
        if (id != "") {
            $.post('/backend/security/bdUserInfo/getById', {id: id}, function (res) {
                if (res.code < 0) {
                    layer.msg(res.message);
                }
                else {
                    $("#bdForm").loadData(res.body);
                    layui.form.render('select');
                }
            });
        }
    })
</script>
</body>
</html>
